package com.rd.student.jiaji.class1.lixin.Exam0808;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class lixin1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        try (BufferedWriter writer = new BufferedWriter(new FileWriter("Student.txt"))) {
            writer.write("姓名 语文成绩 数学成绩 总分");
            writer.newLine();

            for (int i = 1; i <= 3; i++) {
                System.out.println("请输入第" + i + "个学生的信息：");
                System.out.print("姓名：");
                String name = scanner.next();
                System.out.print("语文成绩：");
                int yuwen = scanner.nextInt();
                System.out.print("数学成绩：");
                int shuxue = scanner.nextInt();

                int total = yuwen + shuxue;

                writer.write(name + " " + yuwen + " " + shuxue + " " + total);
                writer.newLine();
            }

            System.out.println("学生信息已录入并写入文件。");
        } catch (IOException e) {
            System.out.println("写入文件失败：" + e.getMessage());
        }
    }
}
